package chapter19;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/4/2 21:19
 */
enum Signal {
    GREEN, YELLOW, RED
}

public class TrafficLight {
    Signal signal = Signal.RED;

    public static void main(String[] args) {
        TrafficLight light = new TrafficLight();
        for (int i = 0; i < 7; i++) {
            System.out.println(light.toString());
            light.change();
        }
    }

    public void change() {
        switch (signal) {
            case RED:
                signal = Signal.GREEN;
                break;
            case GREEN:
                signal = Signal.YELLOW;
                break;
            case YELLOW:
                signal = Signal.RED;
                break;
        }
    }

    @Override
    public String toString() {
        return "The traffic light is " + signal;
    }
}
